package com.cn.common.utils.exception;

import com.cn.common.utils.text.StringUtil;

import java.util.Collection;

public class AssertUtil {
    public AssertUtil() {
    }

    public static void empty(Collection<?> coll, String message) {
        if (StringUtil.isEmpty(coll)) {
            throw new ServiceException(message);
        }
    }

    public static void isNull(Object object, String message) {
        if (object == null) {
            throw new ServiceException(message);
        }
    }

    public static void isNull(Object object, String message, Integer code) {
        if (object == null) {
            throw new ServiceException(message, code);
        }
    }

    public static void empty(Object object, String message) {
        if (object == null || "".equals(object)) {
            throw new ServiceException(message);
        }
    }

    public static void empty(Object object, String message, Integer code) {
        if (object == null || "".equals(object)) {
            throw new ServiceException(message, code);
        }
    }

    public static void isTrue(boolean exp, String message) {
        if (exp) {
            throw new ServiceException(message);
        }
    }

    public static void isTrue(boolean exp, String message, Integer code) {
        if (exp) {
            throw new ServiceException(message, code);
        }
    }

    public static void isFalse(boolean exp, String message) {
        if (!exp) {
            throw new ServiceException(message);
        }
    }

    public static void isFalse(boolean exp, String message, Integer code) {
        if (!exp) {
            throw new ServiceException(message, code);
        }
    }
}